package com.ruoyi.api.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.api.service.FenceService;
import com.ruoyi.api.vo.FenceInfo;
import com.ruoyi.vim.mapper.FenceMapper;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class FenceServiceImpl implements FenceService {

    @Autowired
    private FenceMapper fenceMapper;

    @Override
    public void add(FenceInfo fenceInfo) {
//        Date date = new Date();
//        DateFormat dateFormats = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
//        String times = dateFormats.format(date);
//        fenceInfo.setCreateTime(times);
//        String currentTime = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(Long.valueOf(fenceInfo.getEndForceTime()));
//        fenceInfo.setEndForceTime(currentTime);
//        fenceInfo.setEndForceTime("2023-4-25 19:15:00");
        if(fenceInfo.getFenceShape().equals("3")){
            String[] a = fenceInfo.getFenceGis().split(",");
            fenceInfo.setLon(a[0]);
            fenceInfo.setLat(a[1]);
        }
        fenceMapper.add(fenceInfo);
    }

    @Override
    public boolean delect(Integer fenceId) {
        boolean a = fenceMapper.deleteByid(fenceId);
        return a;
    }

    @Override
    public List<FenceInfo> select(FenceInfo fenceInfo) {
        List<FenceInfo> list = fenceMapper.select(fenceInfo);
        return list;
    }

    @Override
    public boolean update(FenceInfo fenceInfo) {
        return fenceMapper.updates(fenceInfo);
    }

    @Override
    public List<FenceInfo> selectAll() {
        return fenceMapper.selectAllFence();
    }

    @Override
    public FenceInfo selectId(Integer fenceId) {
        return fenceMapper.selectId(fenceId);
    }

    @Override
    public List<FenceInfo> selectPage(Integer page, Integer limit) {
        page = (page - 1) * limit;
        List<FenceInfo> list = fenceMapper.selectPages(page,limit);
        return list;
    }

    @Override
    public Long selectCountPage() {
        return fenceMapper.selectCountPage();
    }


}
